/*
 * Copyright (C) 2013 Daniel Treffenstädt <daniel@treffenstaedt.de>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#ifndef O_CALLBACK_H
#define O_CALLBACK_H

#include "../OGlobal.h"

#include <functional>

O_START_NAMESPACE

template <typename... P> class Functor
{
public:
	virtual ~Functor()
	{}

	inline virtual std::function<void()> operator() (P...) = 0;
};

template <typename C, typename... P> class Callback : public Functor<P...>
{
private:
	C						*m_obj;
	void					(C::*m_func)(P...);

public:
	Callback(C* obj, void (C::*func)(P...))
	{
		m_obj		= obj;
		m_func		= func;
	}

	~Callback()
	{
		m_obj	= 0;
		m_func	= 0;
	}

	inline std::function<void()> operator() (P... param)
	{
		return std::bind(m_func, m_obj, param...);
	}
};

O_END_NAMESPACE



#endif // O_CALLBACK_H
